package com.online.onlineshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.online.onlineshop.entity.Cart;
import com.online.onlineshop.vo.CartValueObject;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CartMapperVOMapper extends BaseMapper<CartValueObject> {

    @Select("<script>"+
            "SELECT\n" +
            "cart.cid,\n" +
            "cart.uid,\n" +
            "cart.pid,\n" +
            "cart.num,\n" +
            "production.title,\n" +
            "production.price AS realPrice,\n" +
            "production.image\n" +
            "FROM\n" +
            "t_cart as cart\n" +
            "LEFT JOIN t_production as production ON cart.pid = production.id\n" +
            "WHERE\n" +
            "cart.cid IN (<foreach collection=\"array\" item=\"cid\" separator=\",\">\n" +
            "#{cid}\n" +
            "</foreach>)\n" +
            "ORDER BY\n" +
            "cart.created_time DESC"+
            "</script>"
          )
    List<CartValueObject> findByCids(Integer[] cids);
}
